package com.hnust.listener;

import com.cleveroom.command.Instruction;
import com.cleveroom.core.KLWCommunicater;
import com.cleveroom.interfaces.IConnectListener;
import com.hnust.entity.CleveroomSensor;
import com.hnust.utils.Message;
import com.hnust.websocket.CleveroomMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 创建人：zhangRuWang
 * 创建时间：2022/4/19
 * 描述：
 */
@Component
public class CleveroomConnListener implements IConnectListener {
    @Autowired
    private CleveroomMessage cleveroomMessage;
    @Autowired
    private KLWCommunicater klwCommunicater;
    @Override
    public void onStatusChange(boolean b) {
        if(b){
            klwCommunicater.asynSend(new Instruction(243, 166, 255, 0, 0, 0, 0));
            klwCommunicater.asynSend(new Instruction(243, 168, 0, 0, 0, 0, 0));
        }
        cleveroomMessage.sendAllMessage(Message.getNetWorkState(
                b?"网络连接正常":"网络已断开"
        ));
    }
}
